import 'package:abc/view/CoinUnlockSheet.dart';
import 'package:abc/view/CustomActionCard.dart';
import 'package:abc/view/CustomInputField.dart';
import 'package:abc/view/KeyboardAwareBottomSheet.dart';
import 'package:abc/view/NonVipCoinUnlockSheet.dart';
import 'package:abc/view/OpenVipUnlockSheet.dart';
import 'package:abc/view/UpLevelUnlockSheet.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class MyPageViewModel extends GetxController {
  void showRedeemCodeSheet(BuildContext context) {
    final textController = TextEditingController();
    showModalBottomSheet<void>(
      context: context,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(20.0)),
      ),
      // 确保键盘弹出时 Bottom Sheet 能自动调整位置
      isScrollControlled: true,
      builder: (BuildContext context) {
        return KeyboardAwareBottomSheet(
          onDismiss: () => Navigator.of(context).pop(),
          child: CustomActionCard(
            onClose: () => Navigator.of(context).pop(),
            iconWidget: Image.asset(
              'assets/images/icon_dhm.png',
              width: 74,
              height: 71,
            ),
            title: '请输入兑换码',
            textController: textController,
            isShowTextFild: true,
            contentWidget: CustomInputField(
              hintText: '请输入兑换码',
              controller: textController,
            ),
            primaryButtonText: '确认',
            onPrimaryButtonPressed: () {
              print('点击兑换');
              Navigator.of(context).pop();
            },
          ),
        );
      },
    );
  }

  void showBusinessCooperationSheet(BuildContext context) {
    showModalBottomSheet<void>(
      context: context,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(20.0)),
      ),

      builder: (BuildContext context) {
        return CustomActionCard(
          onClose: () => Navigator.of(context).pop(),
          iconWidget: Image.asset(
            'assets/images/icon_dhm.png',
            width: 74,
            height: 71,
          ),
          isButtonEnabled: true,
          title: '商务合作',
          contentWidget: Padding(
            padding: EdgeInsets.only(top: 16),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  'TG : @123456',
                  style: TextStyle(
                    fontSize: 18,
                    color: Color(0xFF111111),
                    fontWeight: FontWeight.bold,
                  ),
                ),
                SizedBox(width: 5),
                InkWell(
                  child: Image.asset(
                    'assets/images/icon_copy.png',
                    width: 19,
                    height: 19,
                  ),
                  onTap: () {
                    print('复制');
                  },
                ),
              ],
            ),
          ),
          primaryButtonText: '确认',
          onPrimaryButtonPressed: () {
            print('确认');
            Navigator.of(context).pop();
          },
        );
      },
    );
  }

  void showOfficialTeamGroupSheet(BuildContext context) {
    showModalBottomSheet<void>(
      context: context,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(20.0)),
      ),

      builder: (BuildContext context) {
        return CustomActionCard(
          onClose: () => Navigator.of(context).pop(),
          iconWidget: Image.asset(
            'assets/images/icon_gfqz.png',
            width: 89,
            height: 81,
          ),
          isButtonEnabled: true,
          title: '官方群组',
          contentWidget: Padding(
            padding: EdgeInsets.only(top: 16),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  'TG：1SDE45FV',
                  style: TextStyle(
                    fontSize: 18,
                    color: Color(0xFF111111),
                    fontWeight: FontWeight.bold,
                  ),
                ),
                SizedBox(width: 5),
                InkWell(
                  child: Image.asset(
                    'assets/images/icon_copy.png',
                    width: 19,
                    height: 19,
                  ),
                  onTap: () {
                    print('复制');
                  },
                ),
              ],
            ),
          ),
          primaryButtonText: '确认',
          onPrimaryButtonPressed: () {
            print('确认');
            Navigator.of(context).pop();
          },
        );
      },
    );
  }

  void showInviteCodeSheet(BuildContext context) {
    bool isHasBind = true; //这里是测试用的，如果isHasBind为true，是已绑定状态
    final textController = TextEditingController();
    if (isHasBind) {
      textController.text = 'gafdgfsdgd'; //如果已绑定，这里设置已绑定的邀请码
    }
    showModalBottomSheet<void>(
      context: context,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(20.0)),
      ),
      // 确保键盘弹出时 Bottom Sheet 能自动调整位置
      isScrollControlled: true,
      builder: (BuildContext context) {
        return KeyboardAwareBottomSheet(
          onDismiss: () => Navigator.of(context).pop(),
          child: CustomActionCard(
            onClose: () => Navigator.of(context).pop(),
            iconWidget: Image.asset(
              'assets/images/icon_yqm.png',
              width: 93,
              height: 72,
            ),
            isButtonEnabled: !isHasBind,
            title: '绑定邀请码',
            textController: textController,
            isShowTextFild: true,
            contentWidget: CustomInputField(
              hintText: '请输入邀请码',
              controller: textController,
            ),
            primaryButtonText: isHasBind ? '邀请码已绑定' : '确认绑定',
            footerNotes: Text(
              '注意：只能绑定一次，且绑定后不能进行修改',
              style: TextStyle(
                fontWeight: FontWeight.w400,
                fontSize: 13,
                color: Color(0xFF999999),
              ),
            ),
            onPrimaryButtonPressed: () {
              print('点击绑定');
              Navigator.of(context).pop();
            },
          ),
        );
      },
    );
  }

  void showBottomUnlockSheet({required BuildContext context}) {
    //弹窗1
    // showModalBottomSheet(
    //   context: context,
    //   isScrollControlled: true,
    //   backgroundColor: Colors.white,
    //   shape: const RoundedRectangleBorder(
    //     borderRadius: BorderRadius.only(
    //       topLeft: Radius.circular(15.0),
    //       topRight: Radius.circular(15.0),
    //     ),
    //   ),
    //   builder: (BuildContext context) {
    //     return NonVipCoinUnlockSheet(
    //       costCoin: 10,//原价10金币
    //       memberCost: 9,//会员9金币
    //       currentBalance: 100,//金币余额
    //       onOpenMemberNow: () {
    //         print('点击立即开通');
    //       },
    //       onGoRecharge: () {print('去充值');},
    //       onPayCoin: () {print('支付金币');},
    //     );
    //   },
    // );

    //弹窗2
    //  showModalBottomSheet(
    //   context: context,
    //   isScrollControlled: true,
    //   backgroundColor: Colors.white,
    //   shape: const RoundedRectangleBorder(
    //     borderRadius: BorderRadius.only(
    //       topLeft: Radius.circular(15.0),
    //       topRight: Radius.circular(15.0),
    //     ),
    //   ),
    //   builder: (BuildContext context) {
    //     return CoinUnlockSheet(
    //       costCoin: 10,//原价10金币
    //       currentBalance: 100,//金币余额
    //       onGoRecharge: () {print('去充值');},
    //       onPayCoin: () {print('支付金币');},
    //     );
    //   },
    // );

    //弹窗3
    //    showModalBottomSheet(
    //   context: context,
    //   isScrollControlled: true,
    //   backgroundColor: Colors.white,
    //   shape: const RoundedRectangleBorder(
    //     borderRadius: BorderRadius.only(
    //       topLeft: Radius.circular(15.0),
    //       topRight: Radius.circular(15.0),
    //     ),
    //   ),
    //   builder: (BuildContext context) {
    //     return OpenVipUnlockSheet(
    //       onOpenMemberNow: () {print('立即开通');},
    //       onBecomeVip: () {print('成为会员');},
    //     );
    //   },
    // );

    //弹窗4
    showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      backgroundColor: Colors.white,
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(15.0),
          topRight: Radius.circular(15.0),
        ),
      ),
      builder: (BuildContext context) {
        return UpLevelUnlockSheet(
          currentLevel: 2,
          toLevel: 3,
          onGoRecharge: () {
            print('充值升级');
          },
        );
      },
    );
  }
}
